home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2000 February / Macworld (2000-02).dmg / Updaters / WhiteCap 3.2.2.sea / WhiteCap 3.2.2 / WhiteCap Source / WC_WaveShape.cpp < prev    next >
C/C++ Source or Header  |  1999-10-10  |  7KB  |  200 lines

  1. #include "WC_WaveShape.h"
  2.  
  3. #include "ArgList.h"
  4.  
  5. WC_WaveShape::WC_WaveShape() {
  6.     mPrefWidth = 1;
  7.     mPrefHeight = 1;
  8. }
  9.  
  10.  
  11. #define _assignOrig( field )  field##Orig = field;
  12.  
  13.  
  14.  
  15. void WC_WaveShape::Assign( const ArgList& inArgs, ExpressionDict& ioDict ) {
  16.     UtilStr str;
  17.  
  18.     
  19.     // Extract, compile, and link in order
  20.     mA_Var.Compile( inArgs, 'A', ioDict );        mA_Var.Evaluate();        // The "a"'s are done once per load
  21.     mB_Var.Compile( inArgs, 'B', ioDict );
  22.     mC_Var.Compile( inArgs, 'C', ioDict );
  23.     mD_Var.Compile( inArgs, 'D', ioDict );
  24.         
  25.     inArgs.GetArg( 'X', str );    mX.Compile( str, ioDict );
  26.     inArgs.GetArg( 'Y', str );    mY.Compile( str, ioDict );
  27.     inArgs.GetArg( 'Z', str );    mZ.Compile( str, ioDict );
  28.         
  29.     // Set some basic params
  30.     mBlurVal            = inArgs.GetArg( 'BlrB' );
  31.     mNumBlurs            = inArgs.GetArg( 'Blrs' );
  32.     mSampleDelay        = inArgs.GetArg( 'Resn' );
  33.     mConnectSamples        = inArgs.GetArg( 'ConL' );
  34.     mConnectBins        = inArgs.GetArg( 'ConB' );
  35.     mConnectFirstLast    = inArgs.GetArg( 'ConB' ) > 1;
  36.     mCanIncreaseScale    = inArgs.GetArg( 'ScSz' );
  37.     
  38.     // Change sample expiration/duration from secs to ticks
  39.     mSampleDuration        = 1000.0 * inArgs.GetFloat( 'Durn' );
  40.  
  41.     // Know the preferred X to Y ratio
  42.     mConfigScale        = mXYScale = inArgs.GetArg( 'Scal' );
  43.     mPrefWidth            = inArgs.GetArg( 'widt' );
  44.     mPrefHeight            = inArgs.GetArg( 'heig' );
  45.     mPerspectiveInt        = inArgs.GetFloat( 'Pers' );
  46.     mFalloff            = inArgs.GetFloat( 'Fall' );
  47.  
  48.     // Help make up for the fact that winamp and macamp give us differend data
  49.     #if EG_WIN
  50.     mFalloff *= 0.82;
  51.     #endif    
  52.  
  53.     inArgs.GetArg( 'LWdt', str );
  54.     if ( str.length() == 0 )
  55.         str.Assign( "1" );
  56.     mLineWidth.Compile( str, ioDict );
  57.  
  58.     // How many steps of s from 0 to 1
  59.     mNum_S_Steps = inArgs.GetArg( 'Stps' );
  60.     if ( mNum_S_Steps < 1 )
  61.         mNum_S_Steps = NUM_SAMPLE_BINS;
  62.     if ( mNum_S_Steps > NUM_SAMPLE_BINS )
  63.         mNum_S_Steps = NUM_SAMPLE_BINS;
  64.  
  65.     // Read and compile the camera xyz pos, dir, and angle exprs
  66.     inArgs.GetArg( 'CamX', str );    mCamX.Compile( str, ioDict );
  67.     inArgs.GetArg( 'CamY', str );    mCamY.Compile( str, ioDict );
  68.     inArgs.GetArg( 'CamZ', str );    mCamZ.Compile( str, ioDict );
  69.     inArgs.GetArg( 'CmLX', str );    mCamLX.Compile( str, ioDict );
  70.     inArgs.GetArg( 'CmLY', str );    mCamLY.Compile( str, ioDict );
  71.     inArgs.GetArg( 'CmLZ', str );    mCamLZ.Compile( str, ioDict );
  72.     inArgs.GetArg( 'CUpX', str );    mCamUpX.Compile( str, ioDict );
  73.     inArgs.GetArg( 'CUpY', str );    mCamUpY.Compile( str, ioDict );
  74.     inArgs.GetArg( 'CUpZ', str );    mCamUpZ.Compile( str, ioDict );
  75.         
  76.     // Read and compile color expressions
  77.     inArgs.GetArg( 'R', str );    mR.Compile( str, ioDict );
  78.     inArgs.GetArg( 'G', str );    mG.Compile( str, ioDict );
  79.     inArgs.GetArg( 'B', str );    mB.Compile( str, ioDict );
  80.     if ( inArgs.ArgExists( 'LvlR' ) ) {
  81.         inArgs.GetArg( 'LvlR', str ); mLvlR.Compile( str, ioDict );
  82.         inArgs.GetArg( 'LvlG', str ); mLvlG.Compile( str, ioDict );
  83.         inArgs.GetArg( 'LvlB', str ); mLvlB.Compile( str, ioDict ); }
  84.     else {
  85.         mLvlR.Assign( mR );
  86.         mLvlG.Assign( mG );
  87.         mLvlB.Assign( mB );        
  88.     }
  89.     
  90.     inArgs.GetArg( 'BckR', str );    mBackR.Compile( str, ioDict );
  91.     inArgs.GetArg( 'BckG', str );    mBackG.Compile( str, ioDict );
  92.     inArgs.GetArg( 'BckB', str );    mBackB.Compile( str, ioDict );
  93.  
  94.     mX_Dep_S = mX.IsDependent( "s" ) || mX.IsDependent( "d" ) || mX.IsDependent( "rnd" );
  95.     mY_Dep_S = mY.IsDependent( "s" ) || mY.IsDependent( "d" ) || mX.IsDependent( "rnd" );
  96.     mZ_Dep_S = mZ.IsDependent( "s" ) || mZ.IsDependent( "d" ) || mX.IsDependent( "rnd" );
  97.  
  98.     mR_Dep_S = mR.IsDependent( "s" ) || mR.IsDependent( "d" ) || mX.IsDependent( "rnd" );
  99.     mG_Dep_S = mG.IsDependent( "s" ) || mG.IsDependent( "d" ) || mX.IsDependent( "rnd" );
  100.     mB_Dep_S = mB.IsDependent( "s" ) || mB.IsDependent( "d" ) || mX.IsDependent( "rnd" );
  101.     
  102.     // Make copies of the original values
  103.     _assignOrig( mSampleDuration )
  104.     _assignOrig( mSampleDelay )
  105.     _assignOrig( mFalloff )
  106.     _assignOrig( mNumBlurs )
  107.     _assignOrig( mBlurVal )
  108.     _assignOrig( mPerspectiveInt )
  109.     _assignOrig( mXYScale )
  110.     _assignOrig( mNum_S_Steps )
  111.     _assignOrig( mConnectBins )
  112.     _assignOrig( mConnectSamples )
  113.     _assignOrig( mConnectFirstLast )
  114. }
  115.  
  116.  
  117.  
  118.  
  119. void WC_WaveShape::SetScaleToFit( long inWidth, long inHeight ) {
  120.     float s1, s2;
  121.             
  122.     s1 = mConfigScale * inWidth / mPrefWidth;
  123.     s2 = mConfigScale * inHeight / mPrefHeight; 
  124.     if ( s2 < s1 )
  125.         s1 = s2;
  126.     if ( ! mCanIncreaseScale && s1 > mConfigScale )
  127.         mXYScaleOrig = mConfigScale;
  128.     else
  129.         mXYScaleOrig = s1;
  130.         
  131.     mXYScale = mXYScaleOrig;
  132. }
  133.  
  134.  
  135. void WC_WaveShape::SetupTransition( WC_WaveShape* inDest, float* inC1, float* inC2 ) {
  136.  
  137.     mX.Weight( inDest -> mX, inC1, inC2 );
  138.     mY.Weight( inDest -> mY, inC1, inC2 );
  139.     mZ.Weight( inDest -> mZ, inC1, inC2 );
  140.     
  141.     mCamX.Weight( inDest -> mCamX, inC1, inC2 );
  142.     mCamY.Weight( inDest -> mCamY, inC1, inC2 );    
  143.     mCamZ.Weight( inDest -> mCamZ, inC1, inC2 );
  144.     
  145.     mCamLX.Weight( inDest -> mCamLX, inC1, inC2 );
  146.     mCamLY.Weight( inDest -> mCamLY, inC1, inC2 );
  147.     mCamLZ.Weight( inDest -> mCamLZ, inC1, inC2 );
  148.  
  149.     mCamUpX.Weight( inDest -> mCamUpX, inC1, inC2 );
  150.     mCamUpY.Weight( inDest -> mCamUpY, inC1, inC2 );
  151.     mCamUpZ.Weight( inDest -> mCamUpZ, inC1, inC2 );
  152.     
  153.     mR.Weight( inDest -> mR, inC1, inC2 );
  154.     mG.Weight( inDest -> mG, inC1, inC2 );
  155.     mB.Weight( inDest -> mB, inC1, inC2 );
  156.     
  157.     mLvlR.Weight( inDest -> mLvlR, inC1, inC2 );
  158.     mLvlG.Weight( inDest -> mLvlG, inC1, inC2 );
  159.     mLvlB.Weight( inDest -> mLvlB, inC1, inC2 );
  160.  
  161.     mBackR.Weight( inDest -> mBackR, inC1, inC2 );
  162.     mBackG.Weight( inDest -> mBackG, inC1, inC2 );
  163.     mBackB.Weight( inDest -> mBackB, inC1, inC2 );
  164.         
  165.     mX_Dep_S = mX_Dep_S || inDest -> mX_Dep_S;
  166.     mY_Dep_S = mY_Dep_S || inDest -> mY_Dep_S;
  167.     mZ_Dep_S = mZ_Dep_S || inDest -> mZ_Dep_S;
  168.  
  169.     mR_Dep_S = mR_Dep_S || inDest -> mR_Dep_S;
  170.     mG_Dep_S = mG_Dep_S || inDest -> mG_Dep_S;
  171.     mB_Dep_S = mB_Dep_S || inDest -> mB_Dep_S;
  172.     
  173.     mLineWidth.Weight( inDest -> mLineWidth, inC1, inC2 );
  174.     
  175. }
  176.  
  177.  
  178.  
  179. #define __weightFLT( field ) field = ( inW * ( (float) field##Orig ) + w1 * ( (float) inDest -> field ) );
  180. #define __weightINT( field ) field = ( 0.5 + inW * ( (float) field##Orig ) + w1 * ( (float) inDest -> field ) );
  181. #define __weightBOL( field ) field = .5 < ( inW * ( field##Orig ? 1.0 : 0.0 ) + w1 * ( inDest -> field ? 1.0 : 0.0 ) );
  182.  
  183. void WC_WaveShape::SetupFrame( WC_WaveShape* inDest, float inW ) {
  184.     float w1 = 1.0 - inW;
  185.         
  186.     __weightINT( mSampleDuration )
  187.     __weightINT( mSampleDelay )
  188.     __weightFLT( mFalloff )
  189.     __weightINT( mNumBlurs )
  190.     __weightINT( mBlurVal )
  191.     __weightFLT( mPerspectiveInt )
  192.     __weightFLT( mXYScale )
  193.     __weightINT( mNum_S_Steps )
  194.     __weightBOL( mConnectBins )
  195.     __weightBOL( mConnectSamples )
  196.     __weightBOL( mConnectFirstLast )
  197. }
  198.  
  199.  
  200.